<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>订单列表 - {:think\\facade\\Request::param('site_info')['site_title']}</title>
    <meta name="keywords" content="{:think\\facade\\Request::param('site_info')['site_keyword']}">
    <meta name="description" content="{:think\\facade\\Request::param('site_info')['site_describe']}">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
    <style>
        .layui-table-body .layui-table-cell {
            height: 85px; line-height: 85px;
        }
        .layui-laypage .layui-laypage-curr .layui-laypage-em{ background-color: #1E9FFF; }
        .layui-form-checked[lay-skin=primary] i{border-color: #1E9FFF!important;background-color: #1E9FFF;color:#fff;}
        .layui-form-checkbox[lay-skin=primary]:hover i{border-color:#1E9FFF;color:#fff}
    </style>
</head>
<body>

<div class="layui-fluid">

    <div class="layui-col-md12">
        <div class="layui-card">

            <div lay-filter="listSearch" class="layui-form layui-card-header layuiadmin-card-header-auto" style="height:auto;padding:10px 15px;">

                <div class="layui-form-item">

                    <div class="layui-inline">
                        <select name="quick_id" lay-search>
                            <option value="">选择App</option>
                            {foreach $qas as $v}
                            <option value="{$v->id}">{$v->name}</option>
                            {/foreach}
                        </select>
                    </div>

                    {neq name="role_name" value="channel"}

                    {neq name="role_name" value="agent"}
                    <div class="layui-inline">
                        <select name="agent_id" lay-search>
                            <option value="">选择代理</option>
                            {foreach $agents as $v}
                            <option value="{$v['id']}">{$v['name']}</option>
                            {/foreach}
                        </select>
                    </div>
                    {/neq}

                    <div class="layui-inline">
                        <select name="channel_id" lay-search>
                            <option value="">选择投放号</option>
                            {foreach $channels as $v}
                            <option value="{$v['id']}">{$v['name']}</option>
                            {/foreach}
                        </select>
                    </div>
                    {/neq}

                    <div class="layui-inline">
                        <input type="text" name="order_no" placeholder="请输入订单号" autocomplete="off" class="layui-input">
                    </div>

                    <div class="layui-inline">
                        <input type="text" name="transaction_no" placeholder="请输入交易单号" autocomplete="off" class="layui-input">
                    </div>

                    <div class="layui-inline">
                        <input type="text" name="uid" placeholder="请输入用户ID" autocomplete="off" class="layui-input">
                    </div>

                    <div class="layui-inline">
                        <select name="status" lay-search>
                            <option value="0">支付状态</option>
                            <option value="1">待支付</option>
                            <option value="2">已支付</option>
                            <option value="3">已失效</option>
                            <option value="4">已退款</option>
                        </select>
                    </div>

                    <div class="layui-inline">
                        <input type="number" name="recharge_times" placeholder="请输入充值次数" autocomplete="off" class="layui-input">
                    </div>

                    <div class="layui-inline">
                        <select name="pay_type">
                            <option value="">支付方式</option>
                            <option value="1">微信</option>
                            <option value="2">支付宝</option>
                        </select>
                    </div>

                    <div class="layui-inline">
                        <input type="text" name="link_id" placeholder="链接ID" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-inline">
                        <input type="text" name="nid" placeholder="小说ID" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-inline">
                        <input type="text" name="recharge_activity_id" placeholder="活动ID" autocomplete="off" class="layui-input">
                    </div>


                    <div class="layui-inline">
                        <input type="text" id="user_source_date" name="user_source_date" placeholder="订单归属日期" autocomplete="off" class="layui-input">
                    </div>

                    <div class="layui-inline">
                        <input type="text" id="user_reg_date" name="user_reg_date" placeholder="用户注册日期" autocomplete="off" class="layui-input">
                    </div>

                    <div class="layui-inline">
                        <input type="text" id="dayStart" name="start_date" placeholder="订单开始时间" autocomplete="off" class="layui-input">
                    </div>

                    <div class="layui-inline">
                        <input type="text" id="dayEnd" name="end_date" placeholder="订单结束时间" autocomplete="off" class="layui-input">
                    </div>

                    <div class="layui-inline">
                        <input type="text" name="advertiser_id" placeholder="请输入广告主账户ID" autocomplete="off" class="layui-input">
                    </div>

                    <div class="layui-inline">
                        <input type="text" name="campaign_id" placeholder="请输入广告组ID" autocomplete="off" class="layui-input">
                    </div>

                    <div class="layui-inline">
                        <input type="text" name="aid" placeholder="请输入广告计划ID" autocomplete="off" class="layui-input">
                    </div>

                    <div class="layui-inline">
                        <input type="text" name="cid" placeholder="请输入广告创意ID" autocomplete="off" class="layui-input">
                    </div>


                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-normal layuiadmin-btn-admin" lay-submit lay-filter="LAY-list-front-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                        <button type="button" class="layui-btn layui-btn-primary" lay-submit lay-filter="LAY-reset">重置</button>
                    </div>

                </div>

            </div>

            <div class="layui-card-body">

                <div style="padding-bottom: 10px;">
                    <button class="layui-btn layui-btn-normal layuiadmin-btn-useradmin" data-type="export">导出</button>
                    <p style="display: inline-block;margin-left: 10px;">总金额：<span class="total_amount">0</span></p>
                </div>

                <table id="LAY-list-manage" lay-filter="LAY-list-manage"></table>

                <script type="text/html" id="payStausTpl">
                    <p style="line-height: 30px;">
                        <span style="text-align: left;width: 100%;display:inline-block">
                            {{ d.state }}
                            （{{ d.pay_type }}）
                            {if $role->alias == 'service'}
                            {{#  if(d.is_refund == 0 && d.status == 2){ }}
                              <a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs" lay-event="refund">退款</a>
                              {{#  } }}
                            {/if}
                        </span>
                        <br>
                        <span style="text-align: left;width: 100%;display:inline-block">下单时间：{{ d.create_time }}</span>
                        <br>
                        <span style="text-align: left;width: 100%;display:inline-block">支付时间：{{ d.pay_time }}</span>
                    </p>
                </script>

                <script type="text/html" id="sourceTpl">

                    <span>{{ d.source }}</span>

                </script>

                <script type="text/html" id="reportTpl">

                    <p style="line-height: 36px;">
                        {{ d.report_result }} {{ d.report_hand }} <br />

                        {if ( $role_name == 'channel' ) OR ( $role_name == 'agent' ) }
                        {{#  if(d.status == '2' && d.is_report == '1' ){ }}
                        <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="report">手动上报</a>
                        {{#  } }}
                        {/if}

                    </p>

                </script>

                <script type="text/html" id="rechargeTypeTpl">
                    {{#  if(d.recharge_type == '1'){ }}
                    <span>充值订单</span>
                    {{#  } }}

                    {{#  if(d.recharge_type == '2'){ }}
                    <span>活动订单</span>
                    {{#  } }}
                </script>

                <script type="text/html" id="advertTpl">
                    <p style="line-height: 17px;">
                        <span style="text-align: left;width: 100%;display:inline-block">广告来源：{{ d.media_name }}</span>
                        <br>
                        <span style="text-align: left;width: 100%;display:inline-block">账户ID：{{ d.advertiser_id }}</span>
                        <br>
                        <span style="text-align: left;width: 100%;display:inline-block">计划ID：{{ d.aid }}</span>
                        <br>
                        <span style="text-align: left;width: 100%;display:inline-block">组ID：{{ d.campaign_id }}</span>
                        <br>
                        <span style="text-align: left;width: 100%;display:inline-block">创意ID：{{ d.cid }}</span>
                    </p>
                </script>

                <script type="text/html" id="orderTpl">
                    <div style="line-height: 44px;">
                        <p>{{ d.out_trade_no }}</p>
                        <p>下单IP：{{ d.ip_addr }}</p>
                    </div>
                </script>

                <script type="text/html" id="channelTpl">
                    <div style="line-height: 22px;">
                        {if ( $role_name != 'agent' ) && ( $role_name != 'channel' ) }
                        <p {{#  if(d.agent_remark != ""){ }}lay-tips="{{d.agent_remark}}"{{#  } }}>代理：{{ d.agent_name }}</p>
                        {else /}
                        <p>代理：{{ d.agent_name }}</p>
                        {/if}
                        <p>投放号：{{ d.channel_name }}</p>
                        <p>App：{{ d.quick_name }}</p>
                        <p>推广链接ID：{{ d.link_id }}</p>
                    </div>
                </script>


                <script type="text/html" id="userTpl">
                    <div style="line-height: 45px;">
                        {if ( $role_name == 'admin' ) OR ( $role_name == 'service' ) }
                        <p>
                        <a lay-href="/user/info.html?id={{d.uid}}" lay-text="{{d.uid}} - 读者">{{d.uid}}</a>
                            <br />
                        {else /}
                        <span>{{d.uid}}</span>
                        </p>
                        {/if}
                        <p>注册：{{ d.create_time_user }}</p>
                    </div>
                </script>

            </div>

        </div>
    </div>

</div>

<script src="/static/layuiadmin/layui/layui.js"></script>
<script>

    layui.use('laydate', function () {
        var $ = layui.$;
        var laydate = layui.laydate;

        var nowTime = new Date().valueOf();
        var start = laydate.render({
            elem: '#dayStart',
            type: 'date',
            max: nowTime,
            done: function (value, date) {
                endMax = end.config.max;
                end.config.min = date;
                end.config.min.month = date.month - 1;
            }
        });
        var end = laydate.render({
            elem: '#dayEnd',
            type: 'date',
            max: nowTime,
            done: function (value, date) {
                if ($.trim(value) == '') {
                    var curDate = new Date();
                    date = {
                        'date': curDate.getDate(),
                        'month': curDate.getMonth() + 1,
                        'year': curDate.getFullYear()
                    };
                }
                start.config.max = date;
                start.config.max.month = date.month - 1;
            }
        });

        laydate.render({
            elem: '#user_reg_date',
            type: 'date',
            max: nowTime,
            done: function (value, date) {
                if ($.trim(value) == '') {
                    var curDate = new Date();
                    date = {
                        'date': curDate.getDate(),
                        'month': curDate.getMonth() + 1,
                        'year': curDate.getFullYear()
                    };
                }
            }
        });


        laydate.render({
            elem: '#user_source_date',
            type: 'date',
            max: nowTime,
            done: function (value, date) {
                if ($.trim(value) == '') {
                    var curDate = new Date();
                    date = {
                        'date': curDate.getDate(),
                        'month': curDate.getMonth() + 1,
                        'year': curDate.getFullYear()
                    };
                }
            }
        });

    });

    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','table','admin'], function(){

        var $ = layui.$
            ,form = layui.form
            ,table = layui.table;

        $(document).on("click", ".tab_add", function (){
            top.objOkTab.tabAdd($(this));
        });

        var search_data = '';
        //监听搜索
        form.on('submit(LAY-list-front-search)', function(data){
            var field = data.field;
            search_data = data.field;
            //执行重载
            table.reload('LAY-list-manage', {
                where: field
                ,page: {
                    curr: 1  // 将页码重置为第一页
                }
            });
        });

        form.on('submit(LAY-reset)', function(data){
            form.val("listSearch", {
                "quick_id": "",
                "channel_id": "",
                "order_no": "",
                "agent_id": "",
                "status": "0",
                "uid": "",
                "start_date": "",
                "end_date": "",
                "transaction_no":"",
                "advertiser_id":"",
                "campaign_id":"",
                "aid":"",
                "cid":"",
                "user_source_date":"",
                "user_reg_date":"",
                "pay_type":"",
                "recharge_activity_id":"",
                "link_id":"",
                "nid":"",
                "recharge_times":"",
            });
            form.render();
            table.reload('LAY-list-manage', {
                where: {"quick_id": "","order_no": "","channel_id": "","agent_id": "","status":"0","uid": "","start_date": "","end_date": "","transaction_no":"","advertiser_id":"","campaign_id":"","aid":"","cid":"","user_source_date":"","user_reg_date":"","pay_type":"","recharge_activity_id":"","link_id":"","nid":"","recharge_times":""}
                ,page: {
                    curr: 1  // 将页码重置为第一页
                }
            });
        });

        //书籍管理
        table.render({
            elem: '#LAY-list-manage'
            ,url: "{:url('Order/list_data')}" //模拟接口
            ,autoSort: false
            ,totalRow: true
            ,cols: [[
                {field: 'id', width: 100, title: 'ID', sort: true, align:'center'}
                ,{field: '', title: '订单号', minWidth:200, templet: '#orderTpl'}
                ,{field: '', title: '订单状态', templet: '#payStausTpl', minWidth:220, align:'center'}
                ,{field: '', title: '用户ID', minWidth:200, templet: '#userTpl', align:'center'}
                ,{field: '', title: '投放渠道', minWidth:220, templet: '#channelTpl'}
                ,{field: 'phone_model', title: '手机型号',minWidth:90, align:'center'}
                ,{field: 'total_fee', title: '充值金额', minWidth:120, align:'center'}
                ,{field: 'recharge_info', title: '充值详情', minWidth:140, align:'center'}
                ,{field: 'recharge_times', title: '充值次数', minWidth:90, align:'center'}
                ,{field: '', title: '广告媒介', minWidth:240, templet: '#advertTpl', align:'center'}
                ,{field: '', title: '订单来源', minWidth:240, templet: '#sourceTpl', align:'center'}
                ,{field: 'link_source', title: '来源链接', minWidth:200, align:'center'}
                //,{field: 'create_time_user', title: '激活时间', minWidth:160, align:'center'}
                ,{field: 'recharge_type', title: '类型', minWidth:90, templet: '#rechargeTypeTpl', align:'center'}
                ,{title: '回传状态', width: 150, align:'center',fixed: 'right', toolbar: '#reportTpl'}
            ]]
            ,page: true
            ,limit: 30
            ,height: 'full-100'
            ,text: '对不起，加载出现异常！'
            ,done: function(res, curr, count){
                $('.total_amount').html(res.totalRow.total_fee);
            }
        });

        //触发排序事件
        table.on('sort(LAY-list-manage)', function(obj){

            table.reload('LAY-list-manage', {
                initSort: obj //记录初始排序，如果不设的话，将无法标记表头的排序状态。
                ,where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
                    field: obj.field //排序字段
                    ,order: obj.type //排序方式
                }
            });

        });

        table.on('tool(LAY-list-manage)', function(obj){

            if(obj.event === 'report')
            {
                layer.confirm('确定上报该订单吗？', function(index) {

                    $.ajax({
                        url:"{:url('Order/report')}?id="+obj.data.id,
                        type:"get",
                        dataType: "json",
                        data:{},
                        async:true,
                        success: function(rs){
                            if(rs['code'] == 100){

                                layer.msg(rs['msg'],function () {
                                    layer.close(index);
                                    table.reload('LAY-list-manage');
                                });

                            }else{
                                layer.msg(rs['msg']);
                            }
                            return false;
                        }
                    });

                });
            }

            if(obj.event === 'refund')
            {
                layer.confirm('确定对该笔订单做退款处理吗？', function(index) {
                    console.log(obj.data.id);
                    $.ajax({
                        url:"{:url('Order/refund')}?id="+obj.data.id,
                        type:"get",
                        dataType: "json",
                        data:{},
                        async:true,
                        success: function(rs){
                            if(rs['code'] == 100){

                                layer.msg(rs['msg'],function () {
                                    layer.close(index);
                                    table.reload('LAY-list-manage');
                                });

                            }else{
                                layer.msg(rs['msg']);
                            }
                            return false;
                        }
                    });

                });
            }

        });

        var active = {
            export:function (){
                var queryString = $.param(search_data);
                window.location.href = "{:url('Order/export')}?"+queryString+'';
            }
        };

        $('.layuiadmin-btn-useradmin').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });
</script>
</body>
</html>